import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.features2d.BOWKMeansTrainer;
import org.opencv.features2d.DescriptorExtractor;
import org.opencv.features2d.FeatureDetector;
import org.opencv.imgcodecs.Imgcodecs;

import java.util.ArrayList;
import java.util.List;


public class Test2 {
    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//	      Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
//	      System.out.println( "mat = " + mat.dump() );
        //读取图片
        Mat mat = Imgcodecs.imread("E:/lsll/20161108_184015_000.jpg");

        Mat mat1 = Imgcodecs.imread("E:/lsll/20161108_184015_001.jpg");
        List<Mat> images = new ArrayList<Mat>();
        images.add(mat);
        images.add(mat1);

        //提取图像的ORB特征 根据图像和探测到的关键点来提取特征
        FeatureDetector featureDetector = FeatureDetector.create(FeatureDetector.ORB);
        List<MatOfKeyPoint> keypoints = new ArrayList<MatOfKeyPoint>();
        featureDetector.detect(images, keypoints);

        DescriptorExtractor descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
        List<Mat> descriptors = new ArrayList<Mat>();
        descriptorExtractor.compute(images, keypoints, descriptors);

        //将ORB特征汇总到一个Mat数据结构List<Mat> TrainersMat中
        BOWKMeansTrainer bowkMeansTrainer = new BOWKMeansTrainer(1000);
        List<Mat> TrainersMat = new ArrayList<Mat>();
        Mat clusterMat = null;
        for(Mat descriptor:descriptors){
            clusterMat = bowkMeansTrainer.cluster(descriptor);
            TrainersMat.add(clusterMat);
        }

    }
}
